package cn.com.selfsoft.smartcity.commons.entity;

import cn.com.selfsoft.smartcity.commons.enums.JavaType;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

/**
 * 抽象的key-value实体
 *
 */
public abstract class AbstractKeyValueEntity extends AbstractEntity {
	
	private static final long serialVersionUID = -881747963378403674L;
	
	@NotBlank(message="property must not be blank")
	private String property;
	
	@NotBlank(message="value must not be blank")
	private String value;
	
	@Pattern(regexp="^(String|Integer|Long|Float|Double|BigInteger|BigDecimal|Boolean|LocalDateTime|LocalDate|LocalTime)$", message="javaType is invalid")
	private String javaType;

	public AbstractKeyValueEntity() {
		
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	public String getValue() {
		return value;
	}
	
	public Object getValue(String javaType) {
		return JavaType.parse(javaType, this.value);
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getJavaType() {
		return javaType;
	}

	public void setJavaType(String javaType) {
		this.javaType = javaType;
	}

}
